﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Home.Utils;
using NhanAi.DAO;
using NhanAi.DAO.Mix;
using NhanAi.Entity;
using NhanAi.App_Code;
namespace NhanAi.Admin
{
    public partial class EditComment : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Authenticate();
            SetCurrentPage("Comment");

            int id = TypeWrapper.GetInt32(Request["id"]);
            CommentDao dao = new CommentDao();
            Comment c = dao.Read(id);
            txtAuthor.Text = c.Author;
            txtEmail.Text = c.AuthorEmail;
            if (!IsPostBack)
            {
                txtContent.Text = c.CommentContent;
               
                chkApproved.Checked = c.Approved;
            }
        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {

        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            int id = TypeWrapper.GetInt32(Request["id"]);
            CommentDao dao = new CommentDao();
            bool rs = false;
            try
            {
                Comment c = dao.Read(id);
                c.CommentContent = txtContent.Text;
                c.Approved = chkApproved.Checked;
                dao.Update(c);
                rs = true;
                SetMessage("Cập nhật thành công", "");
            }
            catch (Exception ex)
            {
                SetMessage("Đã xảy ra lỗi", "");
            }
        }
    }
}